import { AsyncStorage } from 'react-native';
import Storage from 'react-native-storage';
const storage = new Storage({
  size: 1000,
  storageBackend: AsyncStorage,
  defaultExpires: null,
  enableCache: true
});

const tokenKey = 'token';
const USER_INFO = 'USERINFO';

export function saveToken(token) {
  console.log('保存了token: ', token);
  storage.save({
    key: tokenKey,
    data: token,
    expires: null
  });
}
// 调用getToken:
// getToken().then(token => token);

export function getToken() {
  return storage.load({
    key: tokenKey
  });
}

export function removeToken() {
  storage.remove({
    key: tokenKey
  });
}

export function saveUserInfo(info) {
  storage.save({
    key: USER_INFO,
    data: info,
    expires: null
  });
}

export function getUserInfo() {
  return storage.load({
    key: USER_INFO
  });
}

export function removeUserInfo() {
  storage.remove({
    key: USER_INFO
  });
}

export default storage;
